const sqlHelper = require('../persist/sqlHelper');
const logger = require('../logs/logger');

module.exports = {
    add(s) {
        logger.debug(`COMMENT: ${JSON.stringify(s)}`);
        var sql = `INSERT INTO \`COMMENT\` (ID, BIZ, MID, IDX, ISTOP, SPEAKER, AVATAR, CONTENT, CREATION, LIKES, REPLIES)
         VALUES (?,?,?,?,?,?,?,?,?,?,?)`;
        var params = [s.id, s.biz, s.mid, s.idx, s.isTop, s.speaker, s.avatar, s.content, s.creation, s.likes, JSON.stringify(s.replies)];

        sqlHelper.execute(conn => {
            conn.query(sql, params, (err, resp) => {
                if (err) {
                    logger.exception(err);
                    return;
                }
                logger.debug(`INSERT COMMENT: ${resp}`);
            });
        });
    }    
};